$(document).ready(function() {
	var current=0;
	var qty = $("#photo_list img").length-1;
	function show(ind){
		current=ind;
	    var src=$("#photo_list img").eq(ind).attr("src");
		$("#photo-temp-wrap img").attr({src:src});
	}
	$("#photo_list img").click(function(){
		var index = $("#photo_list img").index(this);
		show(index);
		$("#photo-temp-wrap").css("display","inherit");
		$("#photo-temp-wrap").animate({"opacity": "1"}, "slow");
		$('#backgr').css("display","inherit");
		//$("#photo-temp-wrap").show('slow');
	});
	$("#close").click(function(){
		$("#photo-temp-wrap").animate({"opacity": "0"}, "slow");
		$("#photo-temp-wrap").css("display","none");
		//$("#photo-temp-wrap").hide("slow");
		$('#backgr').css("display","none");
	});
	$("#setprimary").click(function(){
	    var src=$("#photo_list img").eq(current).attr("src");
	   var ll=src.split('/');
	   $.ajax({
		  type	: "GET",
		  url	: "/changeprphoto",
		  data  :{p_name:	ll[3]	}
	   }).done(function(result){
		   console.log(result);
		   window.location.href="/profile";
	   });
	});
	$('#deletephoto').click(function(){
	    var src=$("#photo_list img").eq(current).attr("src");
		   var ll=src.split('/');
		   $.ajax({
			  type	: "GET",
			  url	: "/deletephoto",
			  data  :{p_name:	ll[3]}
		   }).done(function(result){
			   console.log(result);
			   window.location.reload();
		   });
	});
	$("#rightsid").click(function(){
		if(current+1>qty) show(0);
			else show(current+1);
	});
	$("#leftsid").click(function(){
		if(current-1<0) show(qty);
			else show(current-1);
	});
}); 
